<template>
  <div id="container"></div>
</template>

<script>
import AMapLoader from '@amap/amap-jsapi-loader'
import bus from '@/bus/bus'

window._AMapSecurityConfig = {
  securityJsCode: '84c5f1d65e58c9ac2311b89d390b1e2a'
}
export default {
  name:"mapContainer",
  data() {
    return {
      map: null,
      autoOptions: {
        input: ''
      },
      searchPlaceInput: '',
      auto: null,
      placeSearch: null,
      district: null,
      polygons: [],
      showHeatOrNot: false,
      heatmap: null,
      heatmapList: null
    }
  },
  methods: {
    initMap() {
      AMapLoader.load({
        key: '1360cfb214a46f9d33d796251ce97452', // 申请好的Web端开发者Key，首次调用 load 时必填
        version: '2.0', // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
        plugins: ['AMap.ToolBar', 'AMap.Scale', 'AMap.HawkEye', 'AMap.MapType', 'AMap.Geolocation', 'AMap.AutoComplete', 'AMap.PlaceSearch', 'AMap.Geocoder'] // 需要使用的的插件列表，如比例尺'AMap.Scale'等
      })
        .then(AMap => {
          this.map = new AMap.Map('container', {
            //设置地图容器id
            viewMode: '3D',
            zoom: 10,
            center: [121.473667, 31.230525]
          })
          this.map.addControl(new AMap.Scale())
          this.map.addControl(new AMap.ToolBar())
          this.map.addControl(new AMap.HawkEye())
          this.map.addControl(new AMap.MapType())
          this.map.addControl(new AMap.Geolocation())
          console.log(this.autoOptions)
          console.log(this.auto)
          this.auto = new AMap.AutoComplete(this.autoOptions)
        })
        .catch(e => {
          console.log(e)
        })
    },
  },
  created() {
    bus.$on('shareUserInput', val => {
      console.log(val)
      this.autoOptions.input = val.inputId
    })
  },
  mounted() {
    //DOM初始化完成进行地图初始化
    this.initMap()
  }
}
</script>

<style lang="less">
#container {
  padding: 0px;
  margin: 0px;
  width: 100%;
  height: 100%;
}
</style>

